package com.hyc.myvideo.data.adapter.my.download;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.base.BaseListAdapter;
import com.hyc.myvideo.data.api.model.Download;
import com.hyc.myvideo.utils.imguitl.ImgUitl;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的下载
 * @author gyb
 * @version 1.0
 * @created 2017/07/17
 */
public class DownloadAdapter extends BaseListAdapter<Download> {
    public DownloadAdapter(Context context, List<Download> objects) {
        super(context, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            if (getItemViewType(position) == 0) {
                holder = new ViewHolder();
                //无数据展示
                convertView = inflater.inflate(R.layout.adapter_itme_no, parent, false);
                holder.noDataRootLayout = (LinearLayout) convertView.findViewById(R.id.r_no_id);
            } else {
                convertView = inflater.inflate(R.layout.activity_adapter_download_itme, parent, false);
                holder = new ViewHolder(convertView);
            }
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (hasNoData) {
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(getScreenWidth(), getScreenHeight() * 2 / 3);
            holder.noDataRootLayout.setLayoutParams(lp);
        } else {
            Download download = mDataList.get(position);
            ImgUitl.setImg(download.getImgUrl(), holder.imgCover, R.dimen.app_img_hw60,R.dimen.app_img_hw60);
            holder.textViewTitle.setText(download.getTitle());
            holder.textViewContent.setText(download.getContent());
        }
        return convertView;
    }

    public static class ViewHolder {
        public ViewHolder() {
        }

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        LinearLayout noDataRootLayout;
        //图片
        @BindView(R.id.download_img_cover)
        ImageView imgCover;
        //标题
        @BindView(R.id.download_t_title)
        TextView textViewTitle;
        //内容
        @BindView(R.id.download_t_content)
        TextView textViewContent;
    }
}
